package com.csu.mining.activity;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;

import com.csu.mining.R;
import com.csu.mining.adapters.MiningBottomAdapter;
import com.csu.mining.adapters.MiningGridAdapter;
import com.csu.mining.adapters.MiningMenuAdapter;

import androidx.core.app.ActivityCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;

public class MainActivity extends BaseActivity {
    //读写权限
    private static String[] PERMISSIONS_STORAGE = {
            Manifest.permission.INTERNET,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE
    };
    //请求状态码
    private static int REQUEST_PERMISSION_CODE = 1;
    private RecyclerView mRvGrid;
    private RecyclerView mRvMenu;
    private RecyclerView mRvBottom;
    private MiningGridAdapter miningGridAdapter;
    private MiningMenuAdapter miningMenuAdapter;
    private MiningBottomAdapter miningBottomAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        Instantiation();
    }

    private void initView(){
        initNavBar(true,"首页");
        mRvGrid = fd(R.id.rv_grid);
        mRvMenu = fd(R.id.rv_menu);
        mRvGrid.setLayoutManager(new GridLayoutManager(this,3));
        miningGridAdapter = new MiningGridAdapter(this);
        Log.e("MainActivity","will show recyclerview");
        mRvGrid.setAdapter(miningGridAdapter);
        mRvMenu.setLayoutManager(new GridLayoutManager(this,5));
        miningMenuAdapter = new MiningMenuAdapter(this);
        Log.e("MainActivity","menu will show recyclerview");
        mRvMenu.setAdapter(miningMenuAdapter);
        initBottonBar("home");
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE, REQUEST_PERMISSION_CODE);
            }
        }
    }
}